package com.goods.controller.business;

import com.goods.business.service.SupplierService;
import com.goods.common.model.business.Supplier;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.SupplierVO;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**********************
 *
 *@Author 闫星忠
 *@Time 2021/12/15  18:03
 *
 */

@Api(tags = "业务模块-物资来源相关接口")
@RestController
@RequestMapping("business/supplier")
public class SupplierController {


    @Autowired
    private SupplierService supplierService;



    @ApiOperation(value = "分页展示物资来源信息列表")
    @GetMapping("/findSupplierList")
    public ResponseBean<PageVO<SupplierVO>> findSupplierList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                                           @RequestParam(value = "pageSize") Integer pageSize,
                                                                           SupplierVO supplierVO) {
        PageVO<SupplierVO> supplierList = supplierService.findSupplierList(pageNum, pageSize,supplierVO);
        return ResponseBean.success(supplierList);
    }


    @ApiOperation(value = "添加物资来源信息")
    @PostMapping("/add")
    public ResponseBean add(@RequestBody Supplier supplier){
        supplierService.add(supplier);

        return ResponseBean.success();
    }

    @ApiOperation(value = "编辑页，物资来源信息数据回显")
    @GetMapping("/edit/{id}")
    public ResponseBean<SupplierVO> edit(@PathVariable Long id){
        SupplierVO supplierVO = supplierService.edit(id);
        return ResponseBean.success(supplierVO);
    }

    @ApiOperation(value = "编辑页，数据提交，修改物资来源信息")
    @PutMapping("/update/{id}")
    public ResponseBean update(@PathVariable Long id ,@RequestBody Supplier supplier){
        supplierService.update(id,supplier);
        return ResponseBean.success();
    }


    @ApiOperation(value = "删除物资来源信息")
    @DeleteMapping("/delete/{id}")
    public ResponseBean update(@PathVariable Long id){
            supplierService.delete(id);
        return ResponseBean.success();
    }

    @ApiOperation(value = "添加入库记录页面回显物资来源信息")
    @GetMapping("/findAll")
    public ResponseBean findAll(){
        return ResponseBean.success(supplierService.findAll());
    }

}